package com.zhf.service;

import com.zhf.bean.Grade;
import com.zhf.dao.GradeDao;
import com.zhf.factory.GradeDaoFactory;

import java.sql.SQLException;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/10/24 21:55
 */
public class GradeService {
    private GradeDao gradeDao;


    public GradeService() {
        this.gradeDao= GradeDaoFactory.getGradeDao();
    }

    /**
     * 添加班级
     * @param grade
     * @return
     */
    public boolean addGrade(Grade grade){
        try {
            int i = gradeDao.addGrade(grade);
            if (i>0){
                return true;
            }else {
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 修改班级信息
     * @param grade
     * @return
     */
    public boolean updateGrade(Grade grade){
        try {
            int i = gradeDao.updateGrade(grade);
            if (i>0){
                return true;
            }else {
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 删除班级
     * @param className
     * @return
     */
    public boolean delGrade(String className){
        try {
            int i = gradeDao.delGrade(className);
            if (i>0){
               return true;
            }else {
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 查询班级
     * @param className
     * @return
     */
    public Grade getGrade(String className)  {
        try {
            Grade grade = gradeDao.getGrade(className);
            return grade;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
